package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo12 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection()){
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            conn.setAutoCommit(false);
            String sql="insert into user(username,password,nickname,age) " +
                   "values(?,?,?,?)";
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1,"伟超");
            ps.setString(2,"123456");
            ps.setString(3,"伟超");
            ps.setInt(4,18);
            int num = ps.executeUpdate();
            System.out.println(num>0?"插入成功":"插入失败");
            conn.commit();


        } catch (SQLException throwables) {
            System.out.println("插入失败");
                //conn.rollback();
            throwables.printStackTrace();
        }finally {
            System.out.println("finally");
            //conn.rollback();
        }
    }
}
